PROPERTY:  RegExp::$1, ..., $9

These are properties containing parenthesized substrings (if any) from a regular expression. The number of parenthesized substrings is unlimited, but these properties only hold the last nine. All parenthesized substring, however, can be accessed throught the returned array's indexes. When used as the second argument of the String.replace method, these properties do not require RegExp. before them. In the following example, the day and month parts of a date written in British format are rearranged to American style:

Code:
myRegExp = /(\d{2})\W(\d{2})\W(\d{4})/
dateString = "25/12/1997"
newString = dateString.replace(myRegExp, "$2/$1/$3")
document.write(newString)

Output:
12/25/1997

NOTE:

Because input is static, it is always used as RegExp.input

Copyright 2000 by Infinite Software Solutions, Inc.
Trademark Information